{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "2aa00344",
   "metadata": {},
   "source": [
    "-----------------\n",
    "* 2022/09/13/week04\n",
    "* python课堂笔记\n",
    "----------"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fd946f6d",
   "metadata": {},
   "source": [
    "## 上周回顾（range（）） ：range：范围"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "dff57d68",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "range(0, 5)"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "range(5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "3ba60916",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0\n",
      "1\n",
      "2\n",
      "3\n",
      "4\n"
     ]
    }
   ],
   "source": [
    "# for+range 决定循环的次数\n",
    "for i in range(5):\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "5a5adaf5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "range(1, 5)"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "range(1,5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "282f0e75",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n",
      "2\n",
      "3\n",
      "4\n"
     ]
    }
   ],
   "source": [
    "for i in range(1,5):\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "fa6c9d1a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "range(1, 10, 3)"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 在1-10之间的数间隔3开始记录\n",
    "range(1,10,3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "331c8f0a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n",
      "4\n",
      "7\n"
     ]
    }
   ],
   "source": [
    "for i in range(1,10,3):\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "64fb087b",
   "metadata": {},
   "outputs": [],
   "source": [
    "#  start? stop? step?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "40ad4b31",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 本周内容\n",
    "* type():检查类型\n",
    "\n",
    "\n",
    "\n",
    "> 1.数值\n",
    ">> 1. int\n",
    ">> 2. float\n",
    ">> 3. complex\n",
    "\n",
    "\n",
    "> 2.字符串（是由字符拼接起来的）"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7c4754ab",
   "metadata": {},
   "source": [
    "## 1.Number(数值)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "71ca43cb",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "9 <class 'int'>\n"
     ]
    }
   ],
   "source": [
    "\n",
    "## int\n",
    "\n",
    "a = 9\n",
    "print(a,type(a))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "3fa48f3c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "11.5 <class 'float'>\n"
     ]
    }
   ],
   "source": [
    "## float\n",
    "b = 11.5\n",
    "print(b,type(b))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "a30d959b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(5+3j) <class 'complex'>\n"
     ]
    }
   ],
   "source": [
    "## complex（虚数，复数）\n",
    "c = 5 + 3j\n",
    "print(c,type(c))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6878d6d5",
   "metadata": {},
   "source": [
    "# 2.字符串（string）\n",
    "> 1.关于字符串的基本内容\n",
    "> 2.关于字符串的方法及函数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "799008d1",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Alex <class 'str'>\n"
     ]
    }
   ],
   "source": [
    "name = 'Alex'\n",
    "print(name,type(name))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "18d59731",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Alex <class 'str'>\n"
     ]
    }
   ],
   "source": [
    "name = \"Alex\"\n",
    "print(name,type(name))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "dfdc9488",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Alex <class 'str'>\n"
     ]
    }
   ],
   "source": [
    "name = '''Alex'''\n",
    "print(name,type(name))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "7dc86e32",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"doesn't\""
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"doesn't\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "85112f88",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'hijkjkn\"hkkjl'"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'hijkjkn\"hkkjl'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "50bb176e",
   "metadata": {},
   "outputs": [],
   "source": [
    "### 2.2\n",
    "> 1.字符串的定义\n",
    ">> "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "id": "7ac72341",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "广州南方学院坐落于广州市从化区温泉镇\n"
     ]
    }
   ],
   "source": [
    "# 关于有序性\n",
    "title = \"广州南方学院坐落于广州市从化区温泉镇\"\n",
    "print(title)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "id": "c271a88c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广'"
      ]
     },
     "execution_count": 55,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "title[0] # 取单一值|"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "id": "54db2dd4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "18"
      ]
     },
     "execution_count": 56,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(title) # 检查文本的总长度"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "id": "b071c890",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'镇'"
      ]
     },
     "execution_count": 57,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "title[-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "id": "424caf4d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广州南方学院'"
      ]
     },
     "execution_count": 58,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "title[0:6]  # 取一定范围的值，这种方法我们称为“切片”"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "id": "e8d20350",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广州南方学院'"
      ]
     },
     "execution_count": 59,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "title[:6]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "id": "411f5187",
   "metadata": {},
   "outputs": [],
   "source": [
    "## enumerate 枚举，既可以获取到内容 item，又可以获取到索引值 index"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "id": "a290bf33",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0 广\n",
      "1 州\n",
      "2 南\n",
      "3 方\n",
      "4 学\n",
      "5 院\n",
      "6 坐\n",
      "7 落\n",
      "8 于\n",
      "9 广\n",
      "10 州\n",
      "11 市\n",
      "12 从\n",
      "13 化\n",
      "14 区\n",
      "15 温\n",
      "16 泉\n",
      "17 镇\n"
     ]
    }
   ],
   "source": [
    "## 利用for循环 遍历文本信息\n",
    "for i,j in enumerate(title):\n",
    "    print(i,j)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "id": "4d3bb104",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 思考，如何判断一段文本中是否存在\"广州\",例如文本中的title"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 71,
   "id": "a96fb189",
   "metadata": {},
   "outputs": [],
   "source": [
    "for i,j in enumerate(title):\n",
    "    if i == \"广\":\n",
    "        if title[i+1] == \"州\":\n",
    "            print(\"广州在这段文本中\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 72,
   "id": "f24bab99",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 72,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "## Page59    in检查成员对象\n",
    "\"广州\" in title"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a6801c5b",
   "metadata": {},
   "source": [
    "* 字符串的拼接"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 76,
   "id": "5b54a2f1",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "你好,Alex\n"
     ]
    }
   ],
   "source": [
    "print(\"你好\" + \",\" +  \"Alex\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 78,
   "id": "277d170d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n",
      "1\n"
     ]
    }
   ],
   "source": [
    "print(1)\n",
    "print(\"1\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 79,
   "id": "40f5d7b9",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 <class 'int'>\n",
      "1 <class 'str'>\n"
     ]
    }
   ],
   "source": [
    "print(1,type(1))\n",
    "print(\"1\",type(\"1\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 80,
   "id": "53d1c4d5",
   "metadata": {},
   "outputs": [
    {
     "ename": "TypeError",
     "evalue": "unsupported operand type(s) for /: 'str' and 'str'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
      "Input \u001b[1;32mIn [80]\u001b[0m, in \u001b[0;36m<cell line: 2>\u001b[1;34m()\u001b[0m\n\u001b[0;32m      1\u001b[0m \u001b[38;5;66;03m# 字符串不可以 用来运算\u001b[39;00m\n\u001b[1;32m----> 2\u001b[0m \u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43m3\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m \u001b[49m\u001b[38;5;241;43m/\u001b[39;49m\u001b[43m \u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43m2\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\n",
      "\u001b[1;31mTypeError\u001b[0m: unsupported operand type(s) for /: 'str' and 'str'"
     ]
    }
   ],
   "source": [
    "# 字符串不可以 用来运算\n",
    "\"3\" / \"2\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 84,
   "id": "cba4bb4d",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 由于没有分清楚 字符串和数值概念导致的“笑话”\n",
    "width = \"16\"\n",
    "height = 9"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 85,
   "id": "01c256ac",
   "metadata": {},
   "outputs": [],
   "source": [
    "面积 = width * height"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 86,
   "id": "2ca18ea1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'161616161616161616'"
      ]
     },
     "execution_count": 86,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "面积"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7fed96d7",
   "metadata": {},
   "source": [
    "* 字符串的方法\n",
    "> 1.str.capitalize():可以将首字母转成大写 \n",
    "\n",
    "> 2.str.count():数量？\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 88,
   "id": "efc5025c",
   "metadata": {},
   "outputs": [],
   "source": [
    "name =\"marry\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 90,
   "id": "66aa18a1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Marry'"
      ]
     },
     "execution_count": 90,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "name.capitalize()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 91,
   "id": "97cdc984",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2"
      ]
     },
     "execution_count": 91,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "name.count(\"r\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 92,
   "id": "009e9aae",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广州南方学院坐落于广州市从化区温泉镇'"
      ]
     },
     "execution_count": 92,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "title"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 93,
   "id": "2019e2c3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0"
      ]
     },
     "execution_count": 93,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "title.count(\"新媒体\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 94,
   "id": "eef34464",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['广州南方学院', '广州市从化区温泉镇']"
      ]
     },
     "execution_count": 94,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "title.split(\"坐落于\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "fd9809e6",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
